package com.bestcem.xm.award.controller;

import com.bestcem.xm.award.controller.param.point.CheckSmsCodeParam;
import com.bestcem.xm.award.controller.param.point.SendSmsCodeParam;
import com.bestcem.xm.award.service.AwardSmsService;
import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.common.core.domain.web.XmResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.bestcem.xm.award.constant.PointAwardConstant.FAIL_CODE;

/**
 * 奖励通用短信验证码
 *
 * @author xa.zhang <xa.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/17 14:17
 */
@Slf4j
@RestController
@RequestMapping(value = "/award/v3/sms", produces = MediaType.APPLICATION_JSON_VALUE)
public class AwardSmsController {

    @Resource
    private AwardSmsService awardSmsService;

    /**
     * 奖励通用发送短信验证码
     *
     * @param param 参数
     * @return 结果
     */
    @PostMapping("/sendSmsCode")
    XmResultJson<String> getSmsAuthCode(@RequestBody @Valid SendSmsCodeParam param) {
        ServiceResult serviceGetResult = awardSmsService.getSmsAuthCode(param);
        if (serviceGetResult.isSuccess()) {
            return XmResultJson.success("ok");
        } else {
            return XmResultJson.fail(FAIL_CODE, serviceGetResult.getMsg());
        }
    }

    /**
     * 奖励通用验证短信验证码
     *
     * @param param 参数
     * @return 结果
     */
    @PostMapping("/checkSmsCode")
    XmResultJson<String> checkSmsCode(@RequestBody @Valid CheckSmsCodeParam param) {
        ServiceResult<String> serviceGetResult = awardSmsService.verifySmsAuthCode(param);
        if (serviceGetResult.isSuccess()) {
            return XmResultJson.success("ok");
        } else {
            return XmResultJson.fail(FAIL_CODE, serviceGetResult.getMsg());
        }
    }


}